#include "lolevel.h"
#include "platform.h"
#include "core.h"
#include "conf.h"

static long *nrflag = (long*)0x6718;			// @FF942608 SD940 103c

#include "../../../generic/capt_seq.c"

/*----------------------------------------------------------------------
	capt_seq_task()
-----------------------------------------------------------------------*/
void __attribute__((naked,noinline)) capt_seq_task() {
 asm volatile (
"		STMFD	SP!, {R3-R9,LR} \n"
"		LDR	R6, =0x2988 \n"
"		LDR	R4, =0x37B08 \n"
"		MOV	R9, #1 \n"
"		MOV	R7, #0 \n"
"loc_FF872FF4:\n"
"		LDR	R0, [R6,#4] \n"
"		MOV	R2, #0 \n"
"		MOV	R1, SP \n"
"		BL	sub_FF837DC8 \n"
"		TST	R0, #1 \n"
"		BEQ	loc_FF873020 \n"
"		LDR	R1, =0x5B4 \n"
"		LDR	R0, =0xFF872B70 \n"
"		BL	sub_FF81E88C \n"
"		BL	sub_FF81E844 \n"
"		LDMFD	SP!, {R3-R9,PC} \n"
"loc_FF873020:\n"
"		LDR	R0, [SP] \n"
"		LDR	R1, [R0] \n"
"		CMP	R1, #0x1D \n"
"		ADDLS	PC, PC,	R1,LSL#2 \n"
"		B	loc_FF8732AC \n"

"loc_FF873034:	B	loc_FF8730AC \n"
"loc_FF873038:	B	loc_FF873110 \n"
"loc_FF87303C:	B	loc_FF87314C \n"
"loc_FF873040:	B	loc_FF873160 \n"
"loc_FF873044:	B	loc_FF873158 \n"
"loc_FF873048:	B	loc_FF873168 \n"
"loc_FF87304C:	B	loc_FF873170 \n"
"loc_FF873050:	B	loc_FF873178 \n"
"loc_FF873054:	B	loc_FF8731D0 \n"
"loc_FF873058:	B	loc_FF8731F8 \n"
"loc_FF87305C:	B	loc_FF8731DC \n"
"loc_FF873060:	B	loc_FF8731E8 \n"
"loc_FF873064:	B	loc_FF8731F0 \n"
"loc_FF873068:	B	loc_FF873200 \n"
"loc_FF87306C:	B	loc_FF873208 \n"
"loc_FF873070:	B	loc_FF873210 \n"
"loc_FF873074:	B	loc_FF873218 \n"
"loc_FF873078:	B	loc_FF873220 \n"
"loc_FF87307C:	B	loc_FF87322C \n"
"loc_FF873080:	B	loc_FF873234 \n"
"loc_FF873084:	B	loc_FF87323C \n"
"loc_FF873088:	B	loc_FF873244 \n"
"loc_FF87308C:	B	loc_FF87324C \n"
"loc_FF873090:	B	loc_FF873258 \n"
"loc_FF873094:	B	loc_FF873260 \n"
"loc_FF873098:	B	loc_FF873268 \n"
"loc_FF87309C:	B	loc_FF873270 \n"
"loc_FF8730A0:	B	loc_FF873278 \n"
"loc_FF8730A4:	B	loc_FF873284 \n"
"loc_FF8730A8:	B	loc_FF8732B8 \n"

"loc_FF8730AC:\n"
"		BL	sub_FF873938 \n"
"		BL	shooting_expo_param_override\n"			// added
"		BL	sub_FF870E28 \n"

//  this code added to avoid some incorrect behavior if overrides are used.
 //  but it can cause some unexpected side effects. In this case, remove this code!
		"MOV     R0, #0\n"
        "STR     R0, [R4,#0x24]\n"  // fixes overrides  behavior at short shutter press

"		LDR	R0, [R4,#0x24] \n"
"		CMP	R0, #0 \n"
"		BEQ	loc_FF8732B8 \n"
"		BL	sub_FF872850 \n"
"		MOV	R5, R0 \n"
"		LDR	R0, [R4,#0x24] \n"
"		CMP	R0, #0 \n"
"		BEQ	loc_FF8730F4 \n"
"		MOV	R0, #0xC \n"
"		BL	sub_FF877A7C \n"
"		TST	R0, #1 \n"
"		STRNE	R9, [R6,#0x10] \n"
"		LDRNE	R0, [R5,#8] \n"
"		ORRNE	R0, R0,	#0x40000000 \n"
"		STRNE	R0, [R5,#8] \n"
"		BNE	loc_FF8732B8 \n"

"loc_FF8730F4:\n"
"		MOV	R0, R5 \n"
"		BL	sub_FF872AF4 \n"
"		MOV	R0, R5 \n"

//"		BL	sub_FF9425F4 \n"
"		BL	sub_FF9425F4_my \n"				// patched

"		TST	R0, #1 \n"
"		STRNE	R9, [R6,#0x10] \n"
"		B	loc_FF8732B8 \n"

"loc_FF873110:\n"
"		LDR	R0, [R4,#0x24] \n"
"		CMP	R0, #0 \n"
"		BNE	loc_FF87313C \n"
"		MOV	R0, #0xC \n"
"		BL	sub_FF877A7C \n"
"		TST	R0, #1 \n"
"		LDRNE	R0, [SP] \n"
"		MOVNE	R1, #1 \n"
"		LDRNE	R2, [R0,#0xC] \n"
"		MOVNE	R0, #1 \n"
"		BNE	loc_FF8731C8 \n"

"loc_FF87313C:\n"
"		LDR	R0, [SP] \n"
//"		BL	sub_FF8733D0 \n"
"		BL	sub_FF8733D0_my \n"				// patched

"loc_FF873144:\n"
"		STR	R7, [R4,#0x24] \n"
"		B	loc_FF8732B8 \n"

"loc_FF87314C:\n"
"		MOV	R0, #1 \n"
"		BL	sub_FF873B8C \n"
"		B	loc_FF8732B8 \n"

"loc_FF873158:\n"
"		BL	sub_FF873578 \n"
"		B	loc_FF873144 \n"

"loc_FF873160:\n"
"		BL	sub_FF873918 \n"
"		B	loc_FF873144 \n"

"loc_FF873168:\n"
"		BL	sub_FF873920 \n"
"		B	loc_FF8732B8 \n"

"loc_FF873170:\n"
"		BL	sub_FF873AAC \n"
"		B	loc_FF8731D4 \n"

"loc_FF873178:\n"
"		LDR	R5, [R0,#0xC] \n"
"		BL	sub_FF873928 \n"
"		MOV	R0, R5 \n"
"		BL	sub_FF94140C \n"
"		TST	R0, #1 \n"
"		MOV	R8, R0 \n"
"		BNE	loc_FF8731B8 \n"
"		BL	sub_FF884B34 \n"
"		STR	R0, [R5,#0x18] \n"
"		MOV	R0, R5 \n"
"		BL	sub_FF94250C \n"
"		MOV	R0, R5 \n"
"		BL	sub_FF942908 \n"
"		MOV	R8, R0 \n"
"		LDR	R0, [R5,#0x18] \n"
"		BL	sub_FF884D38 \n"
"loc_FF8731B8:\n"
"		BL	sub_FF873918 \n"
"		MOV	R2, R5 \n"
"		MOV	R1, #9 \n"
"		MOV	R0, R8 \n"
"loc_FF8731C8:\n"
"		BL	sub_FF871314 \n"
"		B	loc_FF8732B8 \n"

"loc_FF8731D0:\n"
"		BL	sub_FF873B0C \n"
"loc_FF8731D4:\n"
"		BL	sub_FF870E28 \n"
"		B	loc_FF8732B8 \n"
"loc_FF8731DC:\n"
"		LDR	R0, [R4,#0x54] \n"
"		BL	sub_FF873F18 \n"
"		B	loc_FF8732B8 \n"
"loc_FF8731E8:\n"
"		BL	sub_FF8741CC \n"
"		B	loc_FF8732B8 \n"
"loc_FF8731F0:\n"
"		BL	sub_FF874260 \n"
"		B	loc_FF8732B8 \n"
"loc_FF8731F8:\n"
"		BL	sub_FF873918 \n"
"		B	loc_FF8732B8 \n"
"loc_FF873200:\n"
"		BL	sub_FF941624 \n"
"		B	loc_FF8732B8 \n"
"loc_FF873208:\n"
"		BL	sub_FF941838 \n"
"		B	loc_FF8732B8 \n"
"loc_FF873210:\n"
"		BL	sub_FF9418D0 \n"
"		B	loc_FF8732B8 \n"
"loc_FF873218:\n"
"		BL	sub_FF9419A0 \n"
"		B	loc_FF8732B8 \n"
"loc_FF873220:\n"
"		MOV	R0, #0 \n"
"		BL	sub_FF941BF0 \n"
"		B	loc_FF8732B8 \n"
"loc_FF87322C:\n"
"		BL	sub_FF941D40 \n"
"		B	loc_FF8732B8 \n"
"loc_FF873234:\n"
"		BL	sub_FF941DD0 \n"
"		B	loc_FF8732B8 \n"
"loc_FF87323C:\n"
"		BL	sub_FF941E90 \n"
"		B	loc_FF8732B8 \n"
"loc_FF873244:\n"
"		BL	sub_FF873D04 \n"
"		B	loc_FF8732B8 \n"
"loc_FF87324C:\n"
"		BL	sub_FF873DA4 \n"
"		BL	sub_FF835F18 \n"
"		B	loc_FF8732B8 \n"
"loc_FF873258:\n"
"		BL	sub_FF941A6C \n"
"		B	loc_FF8732B8 \n"
"loc_FF873260:\n"
"		BL	sub_FF941AD8 \n"
"		B	loc_FF8732B8 \n"
"loc_FF873268:\n"
"		BL	sub_FF87622C \n"
"		B	loc_FF8732B8 \n"
"loc_FF873270:\n"
"		BL	sub_FF876294 \n"
"		B	loc_FF8732B8 \n"
"loc_FF873278:\n"
"		BL	sub_FF8762F0 \n"
"		BL	sub_FF8762B0 \n"
"		B	loc_FF8732B8 \n"
"loc_FF873284:\n"
"		MOV	R0, #1 \n"
"		BL	sub_FF94314C \n"
"		MOV	R0, #1 \n"
"		BL	sub_FF94325C \n"
"		LDRH	R0, [R4,#0x98] \n"
"		CMP	R0, #4 \n"
"		BNE	loc_FF8732B8 \n"
"		BL	sub_FF876294 \n"
"		BL	sub_FF8766D0 \n"
"		B	loc_FF8732B8 \n"

"loc_FF8732AC:\n"
"		LDR	R1, =0x709 \n"
"		LDR	R0, =0xFF872B70 \n"
"		BL	sub_FF81E88C \n"

"loc_FF8732B8:\n"
"		LDR	R0, [SP] \n"
"		LDR	R1, [R0,#4] \n"
"		LDR	R0, [R6] \n"
"		BL	sub_FF87C838 \n"
"		LDR	R5, [SP] \n"
"		LDR	R0, [R5,#8] \n"
"		CMP	R0, #0 \n"
"		LDREQ	R1, =0x132 \n"
"		LDREQ	R0, =0xFF872B70 \n"
"		BLEQ	sub_FF81E88C \n"
"		STR	R7, [R5,#8] \n"
"		B	loc_FF872FF4 \n"
	);
}


/*----------------------------------------------------------------------
	sub_FF94242C_my()  - capt_seq_task()
-----------------------------------------------------------------------*/
void __attribute__((naked,noinline)) sub_FF9425F4_my(){
 asm volatile(
		"STMFD	SP!, {R0-R8,LR}\n"
		"MOV	R4, R0\n"
		"BL		sub_FF943448\n" 
		"MVN     R1, #0\n"  			// MOVL	R1, 0xFFFFFFFF
		"BL		sub_FF87C86C\n"
		"LDR	R5, =0x6718\n"
		"LDR	R0, [R5,#0xC]\n"
		"CMP	R0, #0\n"
		"BNE	loc_FF942644\n"
		"MOV	R1, #1\n"
		"MOV	R0, #0\n"
		"BL		sub_FF838610\n"
		"STR	R0, [R5,#0xC]\n"
		"MOV	R3, #0\n"
		"STR	R3, [SP]\n"				
		"LDR	R3, =0xFF941F80\n"		// SSCaptureSeq.c
		"LDR	R0, =0xFF942870\n"		// aShuttersoundtask
		"MOV	R2, #0x400\n"
		"MOV	R1, #0x17\n"
		"BL		sub_FF8385DC\n"			// KernelCreateTask
"loc_FF942644:\n"
		"MOV	R2, #4\n"
		"ADD	R1, SP,	#0x08\n"
		"MOV	R0, #0x8A\n"
		"BL		sub_FF8849A4\n"			// PT_GetPropertyCaseString_0
		"TST	R0, #1\n"
		"LDRNE	R1, =0x3C5\n"
		"LDRNE	R0, =0xFF942218\n"		// aSscaptureseq_c
		"BLNE	sub_FF81E88C\n"			// DebugAssert
		"LDR	R6, =0x37BCC\n"
		"LDR	R8, =0x37B08\n"
		"LDRSH	R2, [R6,#0xC]\n"
		"LDRSH	R1, [R6,#0xE]\n"
		"LDR	R0, [R8,#0x8C]\n"
		"BL		sub_FF90B5C0\n"
		"BL		sub_FF85BC98\n"			// Thermometer.c
		"LDR	R3, =0x6720\n"
		"STRH	R0, [R4,#0xA4]\n"
		"SUB	R2, R3,	#4\n"
		"STRD	R2, [SP]\n"			
		"MOV	R1, R0\n"
		"LDRH	R0, [R8,#0x5C]\n"
		"LDRSH	R2, [R6,#0xC]\n"
		"SUB	R3, R3,	#8\n"
		"BL		sub_FF944A8C\n"
									
		"BL      wait_until_remote_button_is_released\n"
		"BL      capt_seq_hook_set_nr\n"

		"LDR	R0, [R4,#0x1C]\n"	
		"CMP	R0, #0\n"			
		"MOVNE	R0, #1\n"			
		"STRNE	R0, [R5]\n"			
		"LDR	R0, [R5,#4]\n"		
		"BL		sub_FF90B870\n"		
		"LDR	R0, [R5,#8]\n"		
		"BL		sub_FF8B9EC0\n"		
		"MOV	R0, #1\n"			
		"BL		sub_FF8B9ECC\n"		//nullsub_50		
		"LDR	R0, =0xFF941FF0\n"	
		"MOV	R1, R4\n"			
		"BL		sub_FF8B9E9C\n"		
		"LDR	R0, [R5]\n"			
		"CMP	R0, #5\n"			
		"ADDLS	PC, PC,	R0,LSL#2\n"	
		
		"B		sub_FF9427B0\n"		//go to the ROM
 );
}		
	
	
	
/*----------------------------------------------------------------------
	sub_FF873374_my() - capt_seq_task()
-----------------------------------------------------------------------*/
	void __attribute__((naked,noinline)) sub_FF8733D0_my(){
 asm volatile(
 		"STMFD	SP!, {R4-R6,LR}\n"
		"LDR	R4, [R0,#0xC]\n"
		"LDR	R6, =0x37B08\n"
		"LDR	R0, [R4,#8]\n"
		"MOV	R5, #0\n"
		"ORR	R0, R0,	#1\n"
		"STR	R0, [R4,#8]\n"
		"LDR	R0, [R6,#0x24]\n"
		"CMP	R0, #0\n"
		"MOVEQ	R0, #2\n"
		"BLEQ	sub_FF86F508\n"
		"BL		sub_FF873928\n"
		"LDR	R0, [R6,#0x24]\n"
		"CMP	R0, #0\n"
		"BNE	loc_FF873498\n"
		"MOV	R0, #0\n"
		"BL		sub_FF94314C\n"
		"MOV	R0, #0\n"
		"BL		sub_FF94325C\n"
		"MOV	R0, R4\n"
		"BL		sub_FF873CAC\n"
		"MOV	R0, R4\n"
		"BL		sub_FF94105C\n"
		"CMP	R0, #0\n"
		"BEQ	loc_FF873460\n"
		"BL		sub_FF94318C\n"
		"BL		sub_FF9432A0\n"
		"BL		sub_FF9432F0\n"
		"MOV	R0, R4\n"
		"BL		sub_FF941140\n"
		"TST	R0, #1\n"
		"MOVNE	R2, R4\n"
		"LDMNEFD	SP!, {R4-R6,LR}\n"
		"MOVNE	R1, #1\n"
		"BNE	sub_FF871314\n"
		"B		loc_FF873474\n"
"loc_FF873460:\n"
		"MOV	R0, R4\n"
		"BL		sub_FF9410DC\n"
		"BL		sub_FF94318C\n"
		"BL		sub_FF9432A0\n"
		"BL		sub_FF9432F0\n"
"loc_FF873474:\n"
		"MOV	R0, R4\n"
		"BL		sub_FF872AF4\n"		
		"MOV	R0, R4\n"
		"BL		sub_FF94250C\n"
		"BL		sub_FF942F84\n"
		"MOV	R0, R4\n"
		
// this patch causes a crash when shooting
// it is unknown what the effect is of not calling this	(called elsewhere)	
		"BL		sub_FF9425F4 \n"		
	//	"BL		sub_FF9425F4_my \n"	
		"MOV	R5, R0\n"
		"BL     capt_seq_hook_raw_here\n"  //----------->>
		"B		loc_FF8734A8\n"
// ---------------------------------------------------------------------------

"loc_FF873498:\n"
		"LDR	R0, =0x2988\n"
		"LDR	R0, [R0,#0x10]\n"
		"CMP	R0, #0\n"
		"MOVNE	R5, #0x1D\n"

"loc_FF8734A8:\n"
		"BL		sub_FF876294\n"
		"BL		sub_FF8762DC\n"
		"BL		sub_FF87631C\n"
		"MOV	R2, R4\n"
		"MOV	R1, #1\n"
		"MOV	R0, R5\n"
		"BL		sub_FF871314\n"
		"BL		sub_FF9428AC\n"
		"CMP	R0, #0\n"
		"LDRNE	R0, [R4,#8]\n"
		"ORRNE	R0, R0,	#0x2000\n"
		"STRNE	R0, [R4,#8]\n"
		"LDMFD	SP!, {R4-R6,PC}\n"
	) ;
}


/*----------------------------------------------------------------------
	exp_drv_task()
-----------------------------------------------------------------------*/
void __attribute__((naked,noinline)) exp_drv_task() {
 asm volatile(
		"STMFD	SP!, {R4-R8,LR}\n"
		"SUB	SP, SP,	#0x20\n"
		"LDR	R8, =0xBB8\n"
		"LDR	R7, =0x3C80\n"
		"LDR	R5, =0x3C760\n"
		"MOV	R0, #0\n"
		"ADD	R6, SP, #0x10\n"		
		"STR	R0, [SP, #0x0C]\n" 		
"loc_FF8B2FF0:\n"
		"LDR	R0, [R7,#0x20]\n"
		"MOV	R2, #0\n"
		"ADD	R1, SP, #0x1C\n"		
		"BL		sub_FF837DC8\n"
		"LDR	R0, [SP, #0x0C]\n" 		
		"CMP	R0, #1\n"
		"BNE	loc_FF8B303C\n"
		"LDR	R0, [SP,#0x1C]\n"		
		"LDR	R0, [R0]\n"
		"CMP	R0, #0x13\n"
		"CMPNE	R0, #0x14\n"
		"CMPNE	R0, #0x15\n"
		"CMPNE	R0, #0x16\n"
		"BEQ	loc_FF8B3158\n"
		"CMP	R0, #0x28\n"
		"BEQ	loc_FF8B3130\n"
		"ADD	R1, SP, #0x0C\n" 		
		"MOV	R0, #0\n"
		"BL		sub_FF8B2F80\n"		
"loc_FF8B303C:\n"
		"LDR	R0, [SP,#0x1C]\n"	
		"LDR	R1, [R0]\n"
		"CMP	R1, #0x2D\n"
		"BNE	loc_FF8B306C\n"
		"LDR	R0, [SP,#0x1C]\n"
		"BL		sub_FF8B4240\n"
		"LDR	R0, [R7,#0x1C]\n"
		"MOV	R1, #1\n"
		"BL		sub_FF87C838\n"
		"BL		sub_FF81E844\n"			//eventproc_export_ExitTask\n"
		"ADD	SP, SP,	#0x20\n"
		"LDMFD	SP!, {R4-R8,PC}\n"
"loc_FF8B306C:\n"
		"CMP	R1, #0x2C\n"
		"BNE	loc_FF8B3088\n"
		"LDR	R2, [R0,#0x8C]!\n"
		"LDR	R1, [R0,#4]\n"
		"MOV	R0, R1\n"
		"BLX	R2\n"
		"B		loc_FF8B3580\n"	
"loc_FF8B3088:\n"
		"CMP	R1, #0x26\n"
		"BNE	loc_FF8B30D8\n"
		"LDR	R0, [R7,#0x1C]\n"
		"MOV	R1, #0x80\n"
		"BL		sub_FF87C86C\n"
		"LDR	R0, =0xFF8AF6E0\n"
		"MOV	R1, #0x80\n"
		"BL		sub_FF93641C\n"			// IrisController.c
		"LDR	R0, [R7,#0x1C]\n"
		"MOV	R2, R8\n"
		"MOV	R1, #0x80\n"
		"BL		sub_FF87C778\n"
		"TST	R0, #1\n"
		"LDRNE	R1, =0xE54\n"
		"BNE	loc_FF8B311C\n"
"loc_FF8B30C4:\n"
		"LDR	R1, [SP,#0x1C]\n"	
		"LDR	R0, [R1,#0x90]\n"
		"LDR	R1, [R1,#0x8C]\n"
		"BLX	R1\n"
		"B	loc_FF8B3580\n"	
"loc_FF8B30D8:\n"
		"CMP	R1, #0x27\n"
		"BNE	loc_FF8B3128\n"
		"ADD	R1, SP,	#0xC\n"		
		"BL		sub_FF8B2F80\n"
		"LDR	R0, [R7,#0x1C]\n"
		"MOV	R1, #0x100\n"
		"BL		sub_FF87C86C\n"
		"LDR	R0, =0xFF8AF6F0\n"
		"MOV	R1, #0x100\n"
		"BL		sub_FF9366A4\n"
		"LDR	R0, [R7,#0x1C]\n"
		"MOV	R2, R8\n"
		"MOV	R1, #0x100\n"
		"BL		sub_FF87C778\n"
		"TST	R0, #1\n"
		"BEQ	loc_FF8B30C4\n"
		"LDR	R1, =0xE5E\n"		
"loc_FF8B311C:\n"
		"LDR	R0, =0xFF8AFD54\n"		// aExpdrv_c
		"BL		sub_FF81E88C\n"			// DebugAssert
		"B		loc_FF8B30C4\n"		
"loc_FF8B3128:\n"
		"CMP	R1, #0x28\n"
		"BNE	loc_FF8B3140\n"		
"loc_FF8B3130:\n"
		"LDR	R0, [SP,#0x1C]\n"	
		"ADD	R1, SP,	#0x0C\n"
		"BL		sub_FF8B2F80\n"
		"B		loc_FF8B30C4\n"
"loc_FF8B3140:\n"
		"CMP	R1, #0x2B\n"
		"BNE	loc_FF8B3158\n"
		"BL		sub_FF8A31F0\n"
		"BL		sub_FF8A3E14\n"
		"BL		sub_FF8A3968\n"
		"B		loc_FF8B30C4\n"	
"loc_FF8B3158:\n"
		"LDR	R0, [SP,#0x1C]\n"		
		"MOV	R4, #1\n"
		"LDR	R1, [R0]\n"
		"CMP	R1, #0x11\n"
		"CMPNE	R1, #0x12\n"
		"BNE	loc_FF8B31C8\n"
		"LDR	R1, [R0,#0x7C]\n"
		"ADD	R1, R1,	R1,LSL#1\n"
		"ADD	R1, R0,	R1,LSL#2\n"
		"SUB	R1, R1,	#8\n"
		"LDMIA	R1, {R2-R4}\n"
		"STMIA	R6, {R2-R4}\n"
		"BL		sub_FF8B1894\n"
		"LDR	R0, [SP,#0x1C]\n"	
		"LDR	R1, [R0,#0x7C]\n"
		"LDR	R3, [R0,#0x8C]\n"
		"LDR	R2, [R0,#0x90]\n"
		"ADD	R0, R0,	#4\n"
		"BLX	R3\n"
		"LDR	R0, [SP,#0x1C]\n"	
		"BL		sub_FF8B4600\n"
		"LDR	R0, [SP,#0x1C]\n"	
		"LDR	R1, [R0,#0x7C]\n"
		"LDR	R3, [R0,#0x94]\n"
		"LDR	R2, [R0,#0x98]\n"
		"ADD	R0, R0,	#4\n"
		"BLX	R3\n"
		"B	loc_FF8B34C0\n"
"loc_FF8B31C8:\n"
		"CMP	R1, #0x13\n"
		"CMPNE	R1, #0x14\n"
		"CMPNE	R1, #0x15\n"
		"CMPNE	R1, #0x16\n"
		"BNE	loc_FF8B3280\n"
		"ADD	R3, SP,	#0x0C\n"	
		"MOV	R2, SP\n"
		"ADD	R1, SP,	#0x10\n"	
		"BL		sub_FF8B1B7C\n"
		"CMP	R0, #1\n"
		"MOV	R4, R0\n"
		"CMPNE	R4, #5\n"
		"BNE	loc_FF8B321C\n"
		"LDR	R0, [SP,#0x1C]\n"	
		"MOV	R2, R4\n"
		"LDR	R1, [R0,#0x7C]!\n"
		"LDR	R12, [R0,#0x10]!\n"
		"LDR	R3, [R0,#4]\n"
		"MOV	R0, SP\n"
		"BLX	R12\n"
		"B	loc_FF8B3254\n"		
"loc_FF8B321C:\n"
		"LDR	R0, [SP,#0x1C]\n"	
		"CMP	R4, #2\n"
		"LDR	R3, [R0,#0x90]\n"
		"CMPNE	R4, #6\n"
		"BNE	loc_FF8B3268\n"
		"LDR	R12, [R0,#0x8C]\n"
		"MOV	R0, SP\n"
		"MOV	R2, R4\n"
		"MOV	R1, #1\n"
		"BLX	R12\n"
		"LDR	R0, [SP,#0x1C]\n"	
		"MOV	R2, SP\n"
		"ADD	R1, SP,	#0x10\n"	
		"BL		sub_FF8B2C94\n"
"loc_FF8B3254:\n"
		"LDR	R0, [SP,#0x1C]\n"	
		"LDR	R2, [SP,#0x0D]\n"	
		"MOV	R1, R4\n"
		"BL		sub_FF8B2F20\n"
		"B		loc_FF8B34C0\n"
"loc_FF8B3268:\n"
		"LDR	R1, [R0,#0x7C]\n"
		"LDR	R12, [R0,#0x8C]\n"
		"ADD	R0, R0,	#4\n"
		"MOV	R2, R4\n"
		"BLX	R12\n"
		"B		loc_FF8B34C0\n"
"loc_FF8B3280:\n"
		"CMP	R1, #0x22\n"
		"CMPNE	R1, #0x23\n"
		"BNE	loc_FF8B32CC\n"
		"LDR	R1, [R0,#0x7C]\n"
		"ADD	R1, R1,	R1,LSL#1\n"
		"ADD	R1, R0,	R1,LSL#2\n"
		"SUB	R1, R1,	#8\n"
		"LDMIA	R1, {R2-R4}\n"
		"STMIA	R6, {R2-R4}\n"
		"BL		sub_FF8B0DE4\n"
		"LDR	R0, [SP,#0x1C]\n"	
		"LDR	R1, [R0,#0x7C]\n"
		"LDR	R3, [R0,#0x8C]\n"
		"LDR	R2, [R0,#0x90]\n"
		"ADD	R0, R0,	#4\n"
		"BLX	R3\n"
		"LDR	R0, [SP,#0x1C]\n"
		"BL		sub_FF8B10D8\n"		
		"B		loc_FF8B34C0\n"	
"loc_FF8B32CC:\n"
		"ADD	R1, R0,	#4\n"
		"LDMIA	R1, {R2,R3,R12}\n"
		"STMIA	R6, {R2,R3,R12}\n"
		"LDR	R1, [R0]\n"
		"CMP	R1, #0x25\n"
		"ADDLS	PC, PC,	R1,LSL#2\n"
		"B		loc_FF8B34A0\n"
			
"loc_FF8B32E8:		B	loc_FF8B3380\n"
"loc_FF8B32EC:		B	loc_FF8B3380\n"
"loc_FF8B32F0:		B	loc_FF8B3388\n"
"loc_FF8B32F4:		B	loc_FF8B3390\n"
"loc_FF8B32F8:		B	loc_FF8B3390\n"
"loc_FF8B32FC:		B	loc_FF8B3390\n"
"loc_FF8B3300:		B	loc_FF8B3380\n"
"loc_FF8B3304:		B	loc_FF8B3388\n"
"loc_FF8B3308:		B	loc_FF8B3390\n"
"loc_FF8B330C:		B	loc_FF8B3390\n"
"loc_FF8B3310:		B	loc_FF8B33A8\n"
"loc_FF8B3314:		B	loc_FF8B33A8\n"
"loc_FF8B3318:		B	loc_FF8B3494\n"
"loc_FF8B331C:		B	loc_FF8B349C\n"
"loc_FF8B3320:		B	loc_FF8B349C\n"
"loc_FF8B3328:		B	loc_FF8B349C\n"
"loc_FF8B332C:		B	loc_FF8B34A0\n"
"loc_FF8B3330:		B	loc_FF8B34A0\n"
"loc_FF8B3334:		B	loc_FF8B34A0\n"
"loc_FF8B3338:		B	loc_FF8B34A0\n"
"loc_FF8B333C:		B	loc_FF8B34A0\n"
"loc_FF8B3340:		B	loc_FF8B34A0\n"
"loc_FF8B3344:		B	loc_FF8B3398\n"
"loc_FF8B3348:		B	loc_FF8B33A0\n"
"loc_FF8B334C:		B	loc_FF8B33A0\n"
"loc_FF8B3350:		B	loc_FF8B33B4\n"
"loc_FF8B3354:		B	loc_FF8B33B4\n"
"loc_FF8B3358:		B	loc_FF8B33BC\n"
"loc_FF8B335C:		B	loc_FF8B33EC\n"
"loc_FF8B3360:		B	loc_FF8B341C\n"
"loc_FF8B3364:		B	loc_FF8B344C\n"
"loc_FF8B3368:		B	loc_FF8B347C\n"
"loc_FF8B336C:		B	loc_FF8B347C\n"
"loc_FF8B3370:		B	loc_FF8B34A0\n"
"loc_FF8B3374:		B	loc_FF8B34A0\n"
"loc_FF8B3378:		B	loc_FF8B3484\n"
"loc_FF8B337C:		B	loc_FF8B348C\n"


"loc_FF8B3380:\n"	//		
		"BL		sub_FF8AFBF8\n"
		"B		loc_FF8B34A0\n"
		
"loc_FF8B3388:\n"	//		
		"BL		sub_FF8AFE80\n"
		"B		loc_FF8B34A0\n"
		
"loc_FF8B3390:\n"	//		
		"BL		sub_FF8B0088\n"
		"B		loc_FF8B34A0\n"
		
"loc_FF8B3398:\n"	//
		"BL		sub_FF8B0300\n"
		"B		loc_FF8B34A0\n"

"loc_FF8B33A0:\n"	//
		"BL		sub_FF8B04F8\n"
		"B		loc_FF8B34A0\n"

"loc_FF8B33A8:\n"	//
	//	"BL		sub_FF8B07B4\n" 
		"BL		sub_FF8B07B4_my\n"     //----->>>
		
		"MOV	R4, #0\n"
		"B		loc_FF8B34A0\n"

"loc_FF8B33B4:\n"	//
		"BL		sub_FF8B08F4\n"
		"B		loc_FF8B34A0\n"

"loc_FF8B33BC:\n"	//
		"LDRH	R1, [R0,#4]\n"
		"STRH	R1, [SP,#0x10]\n"
		"LDRH	R1, [R5,#2]\n"
		"STRH	R1, [SP,#0x12]\n"
		"LDRH	R1, [R5,#4]\n"
		"STRH	R1, [SP,#0x14]\n"
		"LDRH	R1, [R5,#6]\n"
		"STRH	R1, [SP,#0x16]\n"
		"LDRH	R1, [R0,#0xC]\n"
		"STRH	R1, [SP,#0x18]\n"
		"BL		sub_FF8B42B4\n"
		"B		loc_FF8B34A0\n"

"loc_FF8B33EC:\n"	
		"LDRH	R1, [R0,#4]\n"
		"STRH	R1, [SP,#0x10]\n"
		"LDRH	R1, [R5,#2]\n"
		"STRH	R1, [SP,#0x12]\n"
		"LDRH	R1, [R5,#4]\n"
		"STRH	R1, [SP,#0x14]\n"
		"LDRH	R1, [R5,#6]\n"
		"STRH	R1, [SP,#0x16]\n"
		"LDRH	R1, [R5,#8]\n"
		"STRH	R1, [SP,#0x18]\n"
		"BL		sub_FF8B4418\n"
		"B		loc_FF8B34A0\n"

"loc_FF8B341C:\n"	//
		"LDRH	R1, [R5]\n"
		"STRH	R1, [SP,#0x10]\n"
		"LDRH	R1, [R0,#6]\n"
		"STRH	R1, [SP,#0x12]\n"	
		"LDRH	R1, [R5,#4]\n"
		"STRH	R1, [SP,#0x14]\n"
		"LDRH	R1, [R5,#6]\n"
		"STRH	R1, [SP,#0x16]\n"
		"LDRH	R1, [R5,#8]\n"
		"STRH	R1, [SP,#0x18]\n"
		"BL		sub_FF8B44C4\n"
		"B		loc_FF8B34A0\n"

"loc_FF8B344C:\n"	//
		"LDRH	R1, [R5]\n"
		"STRH	R1, [SP,#0x10]\n"
		"LDRH	R1, [R5,#2]\n"
		"STRH	R1, [SP,#0x12]\n"
		"LDRH	R1, [R5,#4]\n"
		"STRH	R1, [SP,#0x14]\n"
		"LDRH	R1, [R5,#6]\n"
		"STRH	R1, [SP,#0x16]\n"
		"LDRH	R1, [R0,#0xC]\n"
		"STRH	R1, [SP,#0x18]\n"
		"BL		sub_FF8B4564\n"	
		"B	loc_FF8B34A0\n"

"loc_FF8B347C:\n"	//
		"BL		sub_FF8B0C3C\n"
		"B		loc_FF8B34A0\n"

"loc_FF8B3484:\n"	//
		"BL		sub_FF8B11DC\n"
		"B		loc_FF8B34A0\n"

"loc_FF8B348C:\n"	//
		"BL		sub_FF8B1418\n"
		"B		loc_FF8B34A0\n"
	
"loc_FF8B3494:\n"	//
		"BL		sub_FF8B1594\n"
		"B		loc_FF8B34A0\n"

"loc_FF8B349C:\n"	//
		"BL		sub_FF8B1730\n"

"loc_FF8B34A0:\n"	//
		"LDR	R0, [SP,#0x1C]\n"
		"LDR	R1, [R0,#0x7C]\n"
		"LDR	R3, [R0,#0x8C]\n"
		"LDR	R2, [R0,#0x90]\n"
		"ADD	R0, R0,	#4\n"
		"BLX	R3\n"
		"CMP	R4, #1\n"
		"BNE	loc_FF8B3508\n"

"loc_FF8B34C0:\n"	//
		"LDR	R0, [SP,#0x1C]\n"	
		"MOV	R2, #0xC\n"
		"LDR	R1, [R0,#0x7C]\n"
		"ADD	R1, R1,	R1,LSL#1\n"
		"ADD	R0, R0,	R1,LSL#2\n"
		"SUB	R4, R0,	#8\n"
		"LDR	R0, =0x3C760\n"
		"ADD	R1, SP,	#0x10\n"
		"BL		sub_FFB079A4\n"
		"LDR	R0, =0x3C76C\n"
		"MOV	R2, #0xC\n"
		"ADD	R1, SP,	#0x10\n"
		"BL		sub_FFB079A4\n"
		"LDR	R0, =0x3C778\n"
		"MOV	R2, #0xC\n"
		"MOV	R1, R4\n"
		"BL		sub_FFB079A4\n"
		"B		loc_FF8B3580\n"
"loc_FF8B3508:\n"	//
		"LDR	R0, [SP,#0x1C]\n"
		"LDR	R0, [R0]\n"
		"CMP	R0, #0xB\n"
		"BNE	loc_FF8B3550\n"
		"MOV	R3, #0\n"
		"STR	R3, [SP]\n"	
		"MOV	R3, #1\n"
		"MOV	R2, #1\n"
		"MOV	R1, #1\n"
		"MOV	R0, #0\n"
		"BL		sub_FF8AFA00\n"
		"MOV	R3, #0\n"
		"STR	R3, [SP]\n"	
		"MOV	R3, #1\n"
		"MOV	R2, #1\n"
		"MOV	R1, #1\n"
		"MOV	R0, #0\n"
		"B		loc_FF8B357C\n"
"loc_FF8B3550:\n"	//
		"MOV	R3, #1\n"
		"MOV	R2, #1\n"
		"MOV	R1, #1\n"
		"MOV	R0, #1\n"
		"STR	R3, [SP]\n"	
		"BL		sub_FF8AFA00\n"
		"MOV	R3, #1\n"
		"MOV	R2, #1\n"
		"MOV	R1, #1\n"
		"MOV	R0, #1\n"
		"STR	R3, [SP]\n"	

"loc_FF8B357C:\n"	//	
		"BL		sub_FF8AFB40\n"

"loc_FF8B3580:\n"	//
		"LDR	R0, [SP,#0x1C]\n"	
		"BL		sub_FF8B4240\n"
		"B		loc_FF8B2FF0\n"
 );
}

 
/*----------------------------------------------------------------------
	sub_FF8B07B4_my() - exp_drv_task()
-----------------------------------------------------------------------*/
void __attribute__((naked,noinline)) sub_FF8B07B4_my(){
 asm volatile(
		"STMFD	SP!, {R4-R8,LR}\n"
		"LDR	R7, =0x3C80\n"
		"MOV	R4, R0\n"
		"LDR	R0, [R7,#0x1C]\n"
		"MOV	R1, #0x3E\n"
		"BL		sub_FF87C86C\n"
		"LDRSH	R0, [R4,#4]\n"
		"MOV	R2, #0\n"
		"MOV	R1, #0\n"
		"BL		sub_FF8AF764\n"
		"MOV	R6, R0\n"
		"LDRSH	R0, [R4,#6]\n"
		"BL		sub_FF8AF874\n"
		"LDRSH	R0, [R4,#8]\n"
		"BL		sub_FF8AF8CC\n"
		"LDRSH	R0, [R4,#0xA]\n"
		"BL		sub_FF8AF924\n"
		"LDRSH	R0, [R4,#0xC]\n"
		"MOV	R1, #0\n"
		"BL		sub_FF8AF97C\n"
		"MOV	R5, R0\n"
		"LDR	R0, [R4]\n"
		"LDR	R8, =0x3C778\n"
		"CMP	R0, #0xB\n"
		"MOVEQ	R6, #0\n"
		"MOVEQ	R5, #0\n"
		"BEQ	loc_FF8B0848\n"
		"CMP	R6, #1\n"
		"BNE	loc_FF8B0848\n"
		"LDRSH	R0, [R4,#4]\n"
		"LDR	R1, =0xFF8AF6D0\n"
		"MOV	R2, #2\n"
		"BL		sub_FF936570\n"
		"STRH	R0, [R4,#4]\n"
		"MOV	R0, #0\n"
		"STR	R0, [R7,#0x28]\n"
		"B		loc_FF8B0850\n"
"loc_FF8B0848:\n"	//
		"LDRH	R0, [R8]\n"
		"STRH	R0, [R4,#4]\n"
"loc_FF8B0850:\n"	//
		"CMP	R5, #1\n"
		"LDRNEH	R0, [R8,#8]\n"
		"BNE	loc_FF8B086C\n"
		"LDRSH	R0, [R4,#0xC]\n"
		"LDR	R1, =0xFF8AF754\n"
		"MOV	R2, #0x20\n"
		"BL	sub_FF8B4270\n"
"loc_FF8B086C:\n"	//
		"STRH	R0, [R4,#0xC]\n"
		"LDRSH	R0, [R4,#6]\n"
		
	//	"BL		sub_FF8A2F60\n"   
		"BL		sub_FF8A2F60_my\n"   //------------->>>
		
		"LDRSH	R0, [R4,#8]\n"
		"MOV	R1, #1\n"
		"BL		sub_FF8A36B0\n"
		"MOV	R1, #0\n"
		"ADD	R0, R4,	#8\n"
		"BL		sub_FF8A3738\n"
		"LDRSH	R0, [R4,#0xE]\n"
		"BL		sub_FF8AB224\n"
		"LDR	R4, =0xBB8\n"
		"CMP	R6, #1\n"
		"BNE	loc_FF8B08C4\n"
		"LDR	R0, [R7,#0x1C]\n"
		"MOV	R2, R4\n"
		"MOV	R1, #2\n"
		"BL		sub_FF87C778\n"
		"TST	R0, #1\n"
		"SUBNE	R1, R4,	#0x620\n"
		"LDRNE	R0, =0xFF8AFD54\n"		// aExpdrv_c\n"
		"BLNE	sub_FF81E88C\n"			// DebugAssert\n"
"loc_FF8B08C4:\n"
		"CMP	R5, #1\n"
		"LDMNEFD	SP!, {R4-R8,PC}\n"
		"LDR	R0, [R7,#0x1C]\n"
		"MOV	R2, R4\n"
		"MOV	R1, #0x20\n"
		"BL		sub_FF87C778\n"
		"TST	R0, #1\n"
		"LDRNE	R1, =0x59D\n"
		"LDRNE	R0, =0xFF8AFD54\n"		// aExpdrv_c\n"
		"LDMNEFD	SP!, {R4-R8,LR}\n"
		"BNE	sub_FF81E88C\n"			// DebugAssert
		"LDMFD	SP!, {R4-R8,PC}\n"
	);
}


/*----------------------------------------------------------------------
	sub_FF8A2F60_my() - exp_drv_task()
-----------------------------------------------------------------------*/
void __attribute__((naked,noinline)) sub_FF8A2F60_my(){
 asm volatile(	
		"STMFD	SP!, {R4-R6,LR}\n"
		"LDR	R5, =0x3998\n"
		"MOV	R4, R0\n"
		"LDR	R0, [R5,#4]\n"
		"CMP	R0, #1\n"
		"LDRNE	R1, =0x146\n"
		"LDRNE	R0, =0xFF8A2D64\n"		//aShutter_c
		"BLNE	sub_FF81E88C\n"			// DebugAssert
		"CMN	R4, #0xC00\n"
		"LDREQSH	R4, [R5,#2]\n"
		"CMN	R4, #0xC00\n"
		"MOVEQ	R1, #0x14C\n"
		"LDREQ	R0, =0xFF8A2D64\n"		//aShutter_c
		"STRH	R4, [R5,#2]\n"
		"BLEQ	sub_FF81E88C\n"			// DebugAssert
		"MOV	R0, R4\n"
		
	// "BL	sub_FF9D555C \n "			// old??? apex2us
		"BL		apex2us\n"		//--------------->>
		
		"MOV	R4, R0\n"
//		"BL		nullsub_64\n"
		"MOV	R0, R4\n"
		"BL		sub_FF8DB7D4\n"
		"TST	R0, #1\n"
		"LDRNE	R1, =0x151\n"
		"LDMNEFD	SP!, {R4-R6,LR}\n"
		"LDRNE	R0, =0xFF8A2D64\n"		//aShutter_c
		"BNE	sub_FF81E88C\n"			// DebugAssert
		"LDMFD	SP!, {R4-R6,PC}\n"
	);
}


